import request from '@/utils/request'

// 获取考核统计数据
export function getAssessmentStats() {
  return request({
    url: '/dashboard/assessment/startup/check',
    method: 'get'
  })
}

// 获取最近执行记录
export function getRecentExecutions(params) {
  return request({
    url: '/dashboard/assessment/execute/logs/recent',
    method: 'get',
    params
  })
}

// 配置管理相关API
export function getConfigList(params) {
  return request({
    url: '/dashboard/assessment/config/list',
    method: 'get',
    params
  })
}

export function createConfig(data) {
  return request({
    url: '/dashboard/assessment/config',
    method: 'post',
    data
  })
}

export function updateConfig(id, data) {
  return request({
    url: `/dashboard/assessment/config/${id}`,
    method: 'put',
    data
  })
}

export function deleteConfig(id) {
  return request({
    url: `/dashboard/assessment/config/${id}`,
    method: 'delete'
  })
}

export function toggleSchedule(id, enabled) {
  return request({
    url: `/dashboard/assessment/config/${id}/schedule`,
    method: 'put',
    data: { enabled }
  })
}

export function executeNow(id) {
  return request({
    url: `/dashboard/assessment/config/${id}/execute`,
    method: 'post'
  })
}

// 执行监控相关API
export function getExecuteLogs(params) {
  return request({
    url: '/dashboard/assessment/execute/logs',
    method: 'get',
    params
  })
}


export function retryExecution(configId) {
  return request({
    url: `/dashboard/assessment/execute/retry/${configId}`,
    method: 'post'
  })
}

// 统计分析相关API
export function getStatistics(params) {
  return request({
    url: '/dashboard/assessment/statistics',
    method: 'get',
    params
  })
}

export function getTrendData(params) {
  return request({
    url: '/dashboard/assessment/statistics/trend',
    method: 'get',
    params
  })
}

export function getStatusDistribution(params) {
  return request({
    url: '/dashboard/assessment/statistics/status',
    method: 'get',
    params
  })
}

export function getDurationDistribution(params) {
  return request({
    url: '/dashboard/assessment/statistics/duration',
    method: 'get',
    params
  })
}

export function getConfigRanking(params) {
  return request({
    url: '/dashboard/assessment/statistics/ranking',
    method: 'get',
    params
  })
}

// 分钟级任务相关API
export function createHealthCheckTask() {
  return request({
    url: '/dashboard/assessment/minute/health-check',
    method: 'post'
  })
}

export function createDataMonitorTask(dataType) {
  return request({
    url: '/dashboard/assessment/minute/data-monitor',
    method: 'post',
    params: { dataType }
  })
}

export function createServiceCheckTask() {
  return request({
    url: '/dashboard/assessment/minute/service-check',
    method: 'post'
  })
}

export function createBusinessMetricsTask() {
  return request({
    url: '/dashboard/assessment/minute/business-metrics',
    method: 'post'
  })
}

export function createHighFrequencyMonitorTask(dataType) {
  return request({
    url: '/dashboard/assessment/minute/high-frequency-monitor',
    method: 'post',
    params: { dataType }
  })
}

export function createUltraHighFrequencyMonitorTask() {
  return request({
    url: '/dashboard/assessment/minute/ultra-high-frequency-monitor',
    method: 'post'
  })
}

export function batchCreateMinuteTasks() {
  return request({
    url: '/dashboard/assessment/minute/batch-create',
    method: 'post'
  })
}

export function getMinuteTaskStatistics() {
  return request({
    url: '/dashboard/assessment/minute/statistics',
    method: 'get'
  })
}

// 考核预警相关API
export function getWarningList(params) {
  return request({
    url: '/dashboard/assessment/warning/list',
    method: 'get',
    params
  })
}

export function getWarningById(id) {
  return request({
    url: `/dashboard/assessment/warning/${id}`,
    method: 'get'
  })
}

export function createWarning(data) {
  return request({
    url: '/dashboard/assessment/warning',
    method: 'post',
    data
  })
}

export function updateWarning(id, data) {
  return request({
    url: `/dashboard/assessment/warning/${id}`,
    method: 'put',
    data
  })
}

export function deleteWarning(id) {
  return request({
    url: `/dashboard/assessment/warning/${id}`,
    method: 'delete'
  })
}

export function batchDeleteWarnings(ids) {
  return request({
    url: '/dashboard/assessment/warning/batch',
    method: 'delete',
    data: ids
  })
}

export function markAsRead(id) {
  return request({
    url: `/dashboard/assessment/warning/${id}/read`,
    method: 'put'
  })
}

export function batchMarkAsRead(ids) {
  return request({
    url: '/dashboard/assessment/warning/batch/read',
    method: 'put',
    data: ids
  })
}

export function markAllAsRead(userId) {
  return request({
    url: '/dashboard/assessment/warning/all/read',
    method: 'put',
    params: userId ? { userId } : undefined
  })
}

export function getUnreadCount(userId) {
  return request({
    url: '/dashboard/assessment/warning/unread/count',
    method: 'get',
    params: userId ? { userId } : undefined
  })
}

export function batchMarkAllAsRead(userIds) {
  return request({
    url: '/dashboard/assessment/warning/batch/all/read',
    method: 'put',
    data: userIds
  })
}

export function getWarningStats(userId) {
  return request({
    url: '/dashboard/assessment/warning/stats',
    method: 'get',
    params: { userId }
  })
}

export function deleteExpiredWarnings(days = 30) {
  return request({
    url: '/dashboard/assessment/warning/expired',
    method: 'delete',
    params: { days }
  })
}

// 系统启动相关API
export function checkStartup() {
  return request({
    url: '/dashboard/assessment/startup/check',
    method: 'get'
  })
}

export function startTasks() {
  return request({
    url: '/dashboard/assessment/startup/start',
    method: 'post'
  })
}

export function testTask(configId) {
  return request({
    url: `/dashboard/assessment/startup/test/${configId}`,
    method: 'post'
  })
}
